<?php

/**
 * Distrib form.
 *
 * @package    sf_sandbox
 * @subpackage form
 * @author     Your name here
 * @version    SVN: $Id: sfPropelFormTemplate.php 10377 2008-07-21 07:10:32Z dwhittle $
 */
class DistribForm extends BaseDistribForm
{

public function configure()
  {
  
    $this->setWidget('icon', new sfWidgetFormInputFile());
    
     $this->validatorSchema['icon'] = new sfValidatorFile(array(
        'required'   => true,
        'path'       => sfConfig::get('sf_web_dir').'/uploads/distrib',
        'mime_types' => 'web_images',
        'max_size'   => 380000, // 360 kB
        'validated_file_class' => 'sfPhotoValidatedFile'
        ));
    
    
    $this->embedI18n(array('en_US', 'ru_RU'));
    
  }

 /* 
 public function updateObject($values = null)
  {
    $object = parent::updateObject();
    // путь к аплоду
    $path = sfConfig::get('sf_root_dir').DIRECTORY_SEPARATOR.sfConfig::get('sf_web_dir_name').DIRECTORY_SEPARATOR.sfConfig::get('sf_upload_dir');
    /////
    $object->setIcon(str_replace($path.'/', '', $object->getIcon()));
    return $object;
  }
  
  
 protected function doSave($con = null){
    $values = $this->getValues();
    
    $path = sfConfig::get('sf_root_dir').'/'.
      sfConfig::get('sf_web_dir_name').'/'.sfConfig::get('sf_upload_dir');
    
    if (isset($values['pic_delete'])){
      $currentFile = $path.'/'.$this->getObject()->getIcon();
      if (is_file($currentFile)){
        unlink($currentFile);
      }
      $this->getObject()->setIcon('');
    }

    $file = $values['icon'];

   echo '<pre>'.print_r($values,1).'</pre>';
   // die;
    
    if(!empty($file)){
      if (file_exists(sfConfig::get('sf_upload_dir').'/'.$this->getObject()->getIcon())){
        @unlink($this->getObject()->getIcon());
      }
       $filename = sha1($file->getOriginalName()).$file->getExtension($file->getOriginalExtension());
      $path = sfConfig::get('sf_root_dir').DIRECTORY_SEPARATOR.sfConfig::get('sf_web_dir_name').DIRECTORY_SEPARATOR.sfConfig::get('sf_upload_dir');
      $file->save($path.'/'.$filename);
    }
    
    return parent::doSave($con);
  }
  */
}
